package com.jida.tijian.service;

import com.jida.tijian.domain.Users;
import com.jida.tijian.dto.ResponseObject;
import com.jida.tijian.exception.TijianAPPException;
import com.jida.tijian.exception.TijianAPPExceptionEnum;
import com.jida.tijian.mapper.UsersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ForgetServiceImpl implements ForgetService {
    @Autowired
    UsersMapper usersMapper;

    @Override
    public ResponseObject Repassword(Users users){
        //先查
        Users result = usersMapper.selectByPrimaryKey(users.getUserId());
        //2.看有没有
        if(result == null) {
            //告诉前端
            //responseObject = new ResponseObject<>(201,"该手机号尚未注册");
            throw new TijianAPPException(TijianAPPExceptionEnum.MOBILE_NOT_REGISTER.getCode(),
                    TijianAPPExceptionEnum.MOBILE_NOT_REGISTER.getMessage());
        }
        //3.对比身份证号码
        if(!result.getIdentityCard().equals(users.getIdentityCard())){
            //告诉前端
            //responseObject = new ResponseObject<>(202,"密码错误");
            throw new TijianAPPException(TijianAPPExceptionEnum.IDENTITYCARD_IS_WRONG.getCode(),
                    TijianAPPExceptionEnum.IDENTITYCARD_IS_WRONG.getMessage());
        }
        usersMapper.updateOnlyPassword(users);
        result = usersMapper.selectByPrimaryKey(users.getUserId());
        return new ResponseObject(ResponseObject.SUCCESS_STATUS,ResponseObject.SUCCESS_DESC,result);

    }
}
